﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LogAnProjectUsingFactory
{
    class LogAnalyzerUsingFactory
    {
        private IExtensionManager manager;

        public LogAnalyzerUsingFactory()
        {
            manager = ExtensionManagerFactory.Create();
        }

        public IExtensionManager Manager
        {
            get { return manager; }
            set { manager = value; }
        }

        public bool IsValidLogFileName(string fileName)
        {
            return manager.IsSupportedExtension(fileName);
        }
    }

    public class ExtensionManagerFactory
    {
        private static IExtensionManager m_manager
                        = new FileExtensionManager();

        public static IExtensionManager Create()
        {
            return m_manager;
        }

        public static void SetManagerInstance(IExtensionManager value)
        {
            m_manager = value;
        }
    }
    public class FileExtensionManager : IExtensionManager
    {
        public bool IsSupportedExtension(string fileName)
        {
            //read some file here and determine if it is valid.
            throw new NotImplementedException();
        }
    }
    public interface IExtensionManager
    {
        bool IsSupportedExtension(string fileName);
    }
    public class LogAnalyzerConstructorStub
    {
        private IExtensionManager manager;

        public LogAnalyzerConstructorStub()
        {
            manager = new FileExtensionManager();
        }
        public LogAnalyzerConstructorStub(IExtensionManager extentionMgr)
        {
            manager = extentionMgr;
        }

        public bool IsValidLogFileName(string fileName)
        {
            return manager.IsSupportedExtension(fileName);
        }
    }
}
